<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>企业信息</title>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>

    <link rel="stylesheet" href="../js/libs/sui/sm.min.css">
    <link rel="stylesheet" href="../js/libs/sui/sm-extend.min.css">
    <link rel="stylesheet" href="../iconfont/iconfont.css">
    <link rel="stylesheet" href="../less/main.css"/>

    <script type="text/javascript" src='../js/libs/jquery-3.1.0.min.js' charset='utf-8'></script>
    <script type="text/javascript">
        var Zepto = jQuery;
    </script>
    <script type="text/javascript" src='../js/libs/sui/sm.js' charset='utf-8'></script>
    <script type="text/javascript" src='../js/libs/sui/sm-extend.min.js' charset='utf-8'></script>
    <script type="text/javascript" src="../js/libs/juicer-min.js"></script>
    <script type="text/javascript" src="../js/libs/jquery.md5.js"></script>
    <script type="text/javascript" src="../js/api.js"></script>
    <script type="text/javascript" src="../js/utils.js"></script>
    <script type="text/javascript" src="../js/common.js"></script>
</head>
<body>
<div class="content p-t22 p-b22 bg-default">
    <!-- 头部-->
    <div class="head-no-toolbar bg-self-green no-left-icon">
        <span class="icon iconfont c-white p-l" onclick="javascript:closeWin();">&#xe61f;</span>
        <span class="c-white t-center">企业信息</span>
    </div>
    <div id="cy-company-info" class="company bg-white">
        <!--<div class="company-img border-b">
            <img src="public/images/portrait.jpg" alt="portrait"/>

            <div class="t-center f-bold">贵州安云科技有限公司</div>
        </div>
        <div class="border-b company-detail">
            <div class="row no-gutter">
                <div class="col-20">
                    <span>行业：</span>
                </div>
                <div class="col-80">
                    <span class="c-gray">互联网，计算机软件，产品研发、生产，销售、IT服务</span>
                </div>
            </div>
            <div class="row no-gutter">
                <div class="col-20">
                    <span>性质：</span>
                </div>
                <div class="col-80">
                    <span class="c-gray">民营</span>
                </div>
            </div>
            <div class="row no-gutter">
                <div class="col-20">
                    <span>规模：</span>
                </div>
                <div class="col-80">
                    <span class="c-gray">50-100</span>
                </div>
            </div>
            <div class="row no-gutter">
                <div class="col-20">
                    <span>网址：</span>
                </div>
                <div class="col-80">
                    <span class="c-gray">http://www.boilyun.com/</span>
                </div>
            </div>
        </div>
        <div class="list-block media-list list-m-0">
            <ul id="first-ul">
                <li>
                    <div class="item-link item-content">
                        <div class="item-media"><i class="iconfont icon c-blue">&#xe614;</i></div>
                        <div class="item-inner">
                            <div class="item-subtitle c-gray">
                                贵州贵阳国家高新区金阳科技产业园标准厂房辅助用房B514室
                            </div>
                        </div>
                    </div>
                </li>
            </ul>
        </div>-->
    </div>
    <div id="cy-company-remark" class="company company-panel bg-white">
        <!--<div class="f-bold border-b">公司介绍</div>-->
        <!--<p class="company-intr c-gray">安云科技有限公司成立与2015年4月，是一家以软件、产品开发为主导，集产品研发、生产、销售、服务于一体的高科技企业。</p>-->
    </div>
    <div class="company-job">
        <span class="f-bold">该公司职位</span>
    </div>
    <div id="cy-company-post" class="company bg-white">
        <!--<div class="list-block media-list list-m-0">-->
            <!--<ul>-->
                <!--<li>-->
                    <!--<a class="career-detail block">-->
                        <!--<div class="item-inner">-->
                            <!--<div class="item-title-row">-->
                                <!--<div class="item-title">Java软件工程师</div>-->
                                <!--<div class="item-after f-little">今天</div>-->
                            <!--</div>-->
                            <!--<div class="item-title-row">-->
                                <!--<div class="item-subtitle">贵州安云科技有限公司</div>-->
                                <!--<div class="item-after f-little c-red">6千-8千</div>-->
                            <!--</div>-->
                            <!--<div class="f-little">-->
                                <!--<span class="m-r"><i class="iconfont icon employ-icon">&#xe614;</i><span>贵阳</span></span>-->
                                <!--<span class="m-r"><i class="iconfont icon employ-icon">&#xe61a;</i><span>学历不限</span></span>-->
                            <!--</div>-->
                        <!--</div>-->

                    <!--</a>-->
                <!--</li>-->
            <!--</ul>-->
        <!--</div>-->
        <!--<div class="list-block media-list list-m-0">-->
            <!--<ul>-->
                <!--<li>-->
                    <!--<a class="career-detail block">-->
                        <!--<div class="item-inner">-->
                            <!--<div class="item-title-row">-->
                                <!--<div class="item-title">Java软件工程师</div>-->
                                <!--<div class="item-after f-little">今天</div>-->
                            <!--</div>-->
                            <!--<div class="item-title-row">-->
                                <!--<div class="item-subtitle">贵州安云科技有限公司</div>-->
                                <!--<div class="item-after f-little c-red">6千-8千</div>-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</a>-->
                <!--</li>-->
            <!--</ul>-->
        <!--</div>-->
    </div>
    <div class="botm-btn t-center attent-btn">
        <a id="follow-btn" class="c-white block" href="javascript:void(0);">关注</a>
        <a id="unfollow-btn" class="c-white hide" href="javascript:void(0);">取消关注</a>
    </div>
</div>

<!-- 企业信息模版 -->
<script id="cy-company-info-tpl" type="text/template">
    {@each companyList as it, index}
        <div class="company-img border-b">
            <img src="&{it.PIC_PATH}" />

            {@if (it.UNIT_NAME != null) && (it.UNIT_NAME != '')}
                <div class="t-center f-bold">&{it.UNIT_NAME}</div>
            {@/if}
        </div>
        <div class="border-b company-detail">
            {@if (it.INDUSTRY != null) && (it.INDUSTRY != '')}
                <div class="row no-gutter">
                    <div class="col-20">
                        <span>行业：</span>
                    </div>
                    <div class="col-80">
                        <span class="c-gray">&{it.INDUSTRY}</span>
                    </div>
                </div>
            {@/if}

            {@if (it.UNIT_TYPE != null) && (it.UNIT_TYPE != '')}
                <div class="row no-gutter">
                    <div class="col-20">
                        <span>性质：</span>
                    </div>
                    <div class="col-80">
                        <span class="c-gray">&{it.UNIT_TYPE}</span>
                    </div>
                </div>
            {@/if}

            {@if (it.SCALE != null) && (it.SCALE != '')}
                <div class="row no-gutter">
                    <div class="col-20">
                        <span>规模：</span>
                    </div>
                    <div class="col-80">
                        <span class="c-gray">&{it.SCALE}</span>
                    </div>
                </div>
            {@/if}

            {@if (it.WEBSITE != null) && (it.WEBSITE != '')}
                <div class="row no-gutter">
                    <div class="col-20">
                        <span>网址：</span>
                    </div>
                    <div class="col-80">
                        <span class="c-gray">&{it.WEBSITE}</span>
                    </div>
                </div>
            {@/if}
        </div>

        <div class="list-block media-list list-m-0">
            {@if (it.UNIT_ADDR != null) && (it.UNIT_ADDR != '')}
                <ul id="first-ul">
                    <li>
                        <div class="item-link item-content">
                            <div class="item-media"><i class="iconfont icon c-blue">&#xe614;</i></div>
                            <div class="item-inner">
                                <div class="item-subtitle c-gray">&{it.UNIT_ADDR}</div>
                            </div>
                        </div>
                    </li>
                </ul>
            {@/if}
        </div>
    {@/each}
</script>

<!-- 企业介绍模版 -->
<script id="cy-company-remark-tpl" type="text/template">
    <div class="f-bold border-b">公司介绍</div>

    {@each companyList as it, index}
        {@if (it.REMARKS != null) && (it.REMARKS != '')}
            <p class="company-intr c-gray">$${it.REMARKS}</p>
        {@/if}
    {@/each}
</script>

<!-- 企业职位模版 -->
<script id="cy-company-post-tpl" type="text/template">
    {@each postList as it, index}
    <div class="list-block media-list list-m-0">
        <ul>
            <li>
                <a class="career-detail block" href="javascript:void(0);" data-post-id="&{it.POST_ID}">
                    <div class="item-inner">
                        <div class="item-title-row">
                            {@if (it.POST_NAME != null) && (it.POST_NAME != '')}
                                <div class="item-title">&{it.POST_NAME}</div>
                            {@/if}

                            {@if (beginDates[index] != null) && (beginDates[index] != '')}
                                <div class="item-after">&{beginDates[index]}</div>
                            {@/if}
                        </div>
                        <div class="item-title-row">
                            {@if (unitName != null) && (unitName != '')}
                                <div class="item-subtitle">&{unitName}</div>
                            {@/if}

                            {@if (it.PAY_REMARKS != null) && (it.PAY_REMARKS != '')}
                                <div class="item-after c-red">&{it.PAY_REMARKS}</div>
                            {@/if}
                        </div>
                        <div class="f-little">
                            {@if (it.LOCATION != null) && (it.LOCATION != '')}
                                <span class="m-r"><i class="iconfont icon employ-icon">&#xe614;</i><span>&{it.LOCATION}</span></span>
                            {@/if}

                            {@if (it.EDUCATION_REQ != null) && (it.EDUCATION_REQ != '')}
                                <span class="m-r"><i class="iconfont icon employ-icon">&#xe61a;</i><span>&{it.EDUCATION_REQ}</span></span>
                            {@/if}
                        </div>
                    </div>
                </a>
            </li>
        </ul>
    </div>
    {@/each}
</script>

<script type="text/javascript">
    apiready = function() {
        juicer.set({
            'tag::operationOpen': '{@',
            'tag::operationClose': '}',
            'tag::interpolateOpen': '&{',
            'tag::interpolateClose': '}',
            'tag::noneencodeOpen': '$${',
            'tag::noneencodeClose': '}',
            'tag::commentOpen': '{#',
            'tag::commentClose': '}',
            'strip': false,
            'cache': false
        });
        
        // 获取公司信息 SQL
        var sql1 = "SELECT T.* FROM (SELECT T1.UNIT_ID, T1.UNIT_NAME, T1.AREA_CODE, T1.UNIT_ADDR, T1.LINK_PHONE, T1.REMARKS, T1.PIC_PATH, T1.WEBSITE, ";
        sql1 += "T2.CODE_NAME AS UNIT_TYPE, T3.CODE_NAME AS INDUSTRY, T4.CODE_NAME AS NATURE, T5.CODE_NAME AS SCALE ";
        sql1 += "FROM E_COOPERATION_UNIT T1 ";
        sql1 += "LEFT JOIN SU_CODE_BASE T2 ON T2.CODE_TYPE = 'UNIT_TYPE' AND T1.UNIT_TYPE = T2.CODE ";
        sql1 += "LEFT JOIN SU_CODE_BASE T3 ON T3.CODE_TYPE = 'INDUSTRY' AND T1.INDUSTRY = T3.CODE ";
        sql1 += "LEFT JOIN SU_CODE_BASE T4 ON T4.CODE_TYPE = 'NATURE' AND T1.NATURE = T4.CODE ";
        sql1 += "LEFT JOIN SU_CODE_BASE T5 ON T5.CODE_TYPE = 'SCALE' AND T1.SCALE = T5.CODE ";
        sql1 += "WHERE T1.UNIT_ID = '{0}') T";
        // 获取公司职位 SQL
        var sql2 = "SELECT * FROM E_RECRUIT_POST T WHERE T.UNIT_ID = '{0}'";
        // 获取已关注公司的关注 ID SQL
        var sql3 = "SELECT GROUP_CONCAT(T.FOLLOW_ID SEPARATOR ',') AS FOLLOW_IDS FROM E_FOLLOW T WHERE T.STATE = '1' AND T.STUDENT_ID = '{0}' AND T.UNIT_ID = '{1}' GROUP BY T.STUDENT_ID, T.UNIT_ID";
        // 关注的 SQL
        var sql4 = "INSERT INTO E_FOLLOW(STUDENT_ID, UNIT_ID, STATE, FOLLOW_DATE, CANCEL_DATE) VALUES('{0}', '{1}', 1, NOW(), NULL)";
        // 取消关注的 SQL
        var sql5 = "UPDATE E_FOLLOW T SET T.STATE = '0', T.CANCEL_DATE = NOW() WHERE T.FOLLOW_ID IN ({0})";
        // 获取登录学生的信息
        var stuInfo = null;
        // 已关注公司的关注 ID
        var followIds = "";
        // 关注标志。true-可以关注；false-不可以关注
        var followFlag = false;
        // 取消关注标志。true-可以取消关注；false-不可以取消关注
        var unfollowFlag = false;
        // 公司名称
        var unitName = "";
        // 公司地址
        var unitAddr = "";

        // 如果单位 ID 不为空
        if (isNotEmpty(api.pageParam.unitId)) {
            var tmpSql1 = sql1.format(api.pageParam.unitId);
            var tmpSql2 = sql2.format(api.pageParam.unitId);

            if (isLogin()) {
                stuInfo = getLoginStudentInfo();
            }

            /**
             *
             * 获取关注 ID。
             *
             * @param isLoading 是否显示等待框
             *
             */
            function getFollowIds(isLoading) {
                if (isLogin()) {
                    if (isNotNull(stuInfo) && isNumber(stuInfo.STUDENT_ID)) {
                        var tmpSql3 = sql3.format(stuInfo.STUDENT_ID, api.pageParam.unitId);

                        // 查询是否已关注
                        dbQuery(1, 1, tmpSql3, isLoading, function(ret, err) {
                            // 查询成功
                            if (isObject(ret) && (ret.statusCode == 0)) {
                                // 如果关注 ID 不为空，表示已关注该公司
                                if (isArray(ret.result) && (ret.result.length > 0) && isNotEmpty(ret.result[0].FOLLOW_IDS)) {
                                    followIds = ret.result[0].FOLLOW_IDS;

                                    followFlag = false;
                                    unfollowFlag = true;

                                    $("#follow-btn").removeClass("block").addClass("hide");
                                    $("#unfollow-btn").removeClass("hide").addClass("block");

                                    // 否则表示未关注该公司
                                } else {
                                    followFlag = true;
                                    unfollowFlag = false;

                                    $("#follow-btn").removeClass("hide").addClass("block");
                                    $("#unfollow-btn").removeClass("block").addClass("hide");
                                }

                                // 查询失败
                            } else {
                                followFlag = false;
                                unfollowFlag = false;

                                $("#follow-btn").removeClass("block").addClass("hide");
                                $("#unfollow-btn").removeClass("block").addClass("hide");
                            }
                        });
                    }
                }
            }

            // 查询公司信息
            dbQuery(1, 1, tmpSql1, true, function(ret, err) {
                // 查询成功
                if (isObject(ret) && (ret.statusCode == 0)) {
                    var companyData = {
                        url : getUrl(),
                        companyList : ret.result
                    };

                    $.each(companyData.companyList, function(index, company) {
                        unitName = company.UNIT_NAME;
                        unitAddr = company.UNIT_ADDR;

                        // 整理数据
                        if (isEmpty(unitName)) {
                            unitName = "";
                        }

                        if (isEmpty(unitAddr)) {
                            unitAddr = "";
                        }

                        // 添加默认图片
                        if (isEmpty(company.PIC_PATH)) {
                            company.PIC_PATH = "../images/no_png.png";
                        } else {
                            company.PIC_PATH = "{0}{1}".format(companyData.url, company.PIC_PATH);
                        }

                        if (isNotEmpty(company.INDUSTRY) && isNotEmpty(company.NATURE)) {
                            company.INDUSTRY = (company.INDUSTRY + "，" + company.NATURE);
                        } else if (isEmpty(company.INDUSTRY) && isEmpty(company.NATURE)) {
                            company.INDUSTRY = "";
                        } else if (isEmpty(company.INDUSTRY) && isNotEmpty(company.NATURE)) {
                            company.INDUSTRY = company.NATURE;
                        }

                        if (isEmpty(company.UNIT_TYPE)) {
                            company.UNIT_TYPE = "";
                        }

                        if (isEmpty(company.SCALE)) {
                            company.SCALE = "";
                        }

                        if (isEmpty(company.WEBSITE)) {
                            company.WEBSITE = "";
                        }

                        // 只执行一次即可
                        return false;
                    });
//
                    $("#cy-company-info").html(juicer($("#cy-company-info-tpl").html(), companyData));
                    $("#cy-company-remark").html(juicer($("#cy-company-remark-tpl").html(), companyData));
                }
            });

            // 查询公司职位
            dbQuery(1, 10, tmpSql2, true, function(ret, err) {
                // 查询成功
                if (isObject(ret) && (ret.statusCode == 0)) {
                    var postData = {
                        url : getUrl(),
                        postList : ret.result,
                        unitName : unitName,
                        unitAddr : unitAddr,
                        beginDates : []
                    };

                    $.each(postData.postList, function(index, post) {
                        if (isEmpty(post.BEGIN_DATE)) {
                            postData.beginDates.push("");
                        } else {
                            postData.beginDates.push(new Date(post.BEGIN_DATE).format("M月d日"));
                        }
                    });

                    $("#cy-company-post").html(juicer($("#cy-company-post-tpl").html(), postData));
                }
            });

            // 获取关注 ID
            getFollowIds(true);

            // 点击展示职位详情
            $("#cy-company-post").on("click", ".career-detail", function() {
                var $this = $(this);

                openWin("career-detail", "career-detail.html", {
                    unitId : api.pageParam.unitId,
                    postId : $this.data("postId"),
                    unitName : unitName,
                    unitAddr : unitAddr
                });
            });

            // 点击关注
            $("#follow-btn").click(function() {
                if (isLogin()) {
                    if (followFlag) {
                        if (isNotNull(stuInfo) && isNumber(stuInfo.STUDENT_ID)) {
                            followFlag = false;

                            var tmpSql4 = sql4.format(stuInfo.STUDENT_ID, api.pageParam.unitId);

                            // 关注
                            dbExecute(tmpSql4, true, function(ret, err) {
                                // 执行成功
                                if (isObject(ret) && (ret.statusCode == 0)) {
                                    toast("关注成功");

                                    // 获取关注 ID
                                    getFollowIds(true);

                                    //发送关注事件
                                    api.sendEvent({
                                        name: "companyEvent"
                                    });

                                    // 执行失败
                                } else {
                                    toast("关注失败，稍后再试");

                                    followFlag = true;
                                    unfollowFlag = false;

                                    $("#follow-btn").removeClass("hide").addClass("block");
                                    $("#unfollow-btn").removeClass("block").addClass("hide");
                                }
                            });
                        }
                    }
                } else {
                    toLogin();
                }
            });

            // 点击取消关注
            $("#unfollow-btn").click(function() {
                if (isLogin()) {
                    if (unfollowFlag) {
                        if (isNotEmpty(followIds)) {
                            unfollowFlag = false;

                            var tmpFollowIds = followIds.split(",");
                            var tmpFollowIdsStr= "";

                            for (var i = 0; i < tmpFollowIds.length; i++) {
                                if (tmpFollowIds.length == 1) {
                                    tmpFollowIdsStr += ("'" + tmpFollowIds[i] + "'");
                                } else {
                                    if (i < (tmpFollowIds.length - 1)) {
                                        tmpFollowIdsStr += ("'" + tmpFollowIds[i] + "',");
                                    } else {
                                        tmpFollowIdsStr += ("'" + tmpFollowIds[i] + "'");
                                    }
                                }
                            }

                            var tmpSql5 = sql5.format(tmpFollowIdsStr);

                            // 取消关注
                            dbExecute(tmpSql5, true, function(ret, err) {
                                // 执行成功
                                if (isObject(ret) && (ret.statusCode == 0)) {
                                    toast("取消关注成功");

                                    getFollowIds(true);

                                    //发送关注事件
                                    api.sendEvent({
                                        name: "companyEvent"
                                    });

                                    // 执行失败
                                } else {
                                    toast("取消关注失败，稍后再试");

                                    followFlag = false;
                                    unfollowFlag = true;

                                    $("#follow-btn").removeClass("block").addClass("hide");
                                    $("#unfollow-btn").removeClass("hide").addClass("block");
                                }
                            });
                        }
                    }
                } else {
                    toLogin();
                }
            });

            // 监听登录事件
            api.addEventListener({
                name: "loginEvent"
            }, function(ret, err) {
                stuInfo = getLoginStudentInfo();

                // 获取关注 ID
                getFollowIds(true);
            });
        }
    };
</script>
</body>
</html>